package com.groupbuying.store.controller.forInternal;

import com.groupbuying.store.dto.LoginDTO;
import com.groupbuying.store.service.StoreAccountService;
import com.groupbuying.store.service.forManage.StoreMenuService;
import com.groupbuying.store.service.forManage.TokenService;
import com.groupbuying.store.utils.R;
import com.groupbuying.store.utils.apiresult.ApiResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Map;

/**
 * @author ywxd
 * @version V1.0
 */

@Api("服务商登录")
@RequestMapping()
@RestController
public class StoreLoginController {
    @Autowired
    StoreAccountService storeAccountService;
    @Autowired
    TokenService tokenService;
    @Autowired
    StoreMenuService storeMenuService;

    //@Log("登录")
    @PostMapping("/login")
    public R login(@Valid @RequestBody LoginDTO loginDTO, HttpServletRequest request, HttpServletResponse response) {
        return storeAccountService.internal_login(loginDTO);
    }

    @RequestMapping("/logout")
    public R logout(HttpServletRequest request, HttpServletResponse response) {
        //menuService.clearCache(FilterContextHandler.getUserID());
        return R.ok();
    }

    //移动端获取信息
    @GetMapping("/getNameAndNoForMobi")
    public ApiResult getNameAndNoForMobi(){
        return storeAccountService.getByAccountId();
    }

    /**
    * @author grj
    * @des    移动端服务商登录
    * @modif  zmlmagic
    * */
    @PostMapping("/loginStore")
    public ApiResult loginStore(@RequestParam Map<String,Object> map) {
        return storeAccountService.loginForStore(map);
    }
}
